package com.cloudservice.ccs.model;

import com.cloudservice.ccs.entity.WorkloadStatistics;
import lombok.Data;

@Data
public class WorkloadStatisticsWithAverage extends WorkloadStatistics {

    private Integer averageSessionTime;

    private Integer averageMessageCount;

    public static WorkloadStatisticsWithAverage fromWorkloadStatistics(WorkloadStatistics workloadStatistics) {
        WorkloadStatisticsWithAverage res = new WorkloadStatisticsWithAverage();
        res.setId(workloadStatistics.getId());
        res.setNickName(workloadStatistics.getNickName());
        res.setTotalMessageCount(workloadStatistics.getTotalMessageCount());
        res.setTotalSessionCount(workloadStatistics.getTotalSessionCount());
        res.setTotalEffectiveSessionCount(workloadStatistics.getTotalEffectiveSessionCount());
        res.setTotalEndSessionCount(workloadStatistics.getTotalEndSessionCount());
        res.setTotalSessionTime(workloadStatistics.getTotalSessionTime());
        return res;
    }

    public void calculateAverage() {
        this.setAverageSessionTime(this.getTotalSessionTime() / this.getTotalSessionCount());
        this.setAverageMessageCount(this.getTotalMessageCount() / this.getTotalSessionCount());
    }
}
